import 'package:flutter/material.dart';

import '../../utils/message.dart';
import '../../widgets/qrcode_reader.dart';

class ScanViewDemo extends StatefulWidget {
  ScanViewDemo({Key key}) : super(key: key);

  @override
  _ScanViewDemoState createState() => new _ScanViewDemoState();
}

class _ScanViewDemoState extends State<ScanViewDemo> {
  GlobalKey<QrcodeReaderState> _key = GlobalKey();
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return QrcodeReader(
      key: _key,
      onScan: onScan,
      headerWidget: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0.0,
      ),
    );
  }

  Future onScan(String data) async {
    await MessageUtil.alert(context, data, title: '扫码结果');
    _key.currentState.startScan();
  }

  @override
  void dispose() {
    super.dispose();
  }
}
